<?php

    $menu = $viewModel->getMenu();
    
    if (!Auth::isAuthenticated() || !isset($menu)) {
        return;
    }

    $active = $this->getModule();
    if ($active === null) {
        $active = $this->getName();
    }

    $contentMenuItem = $menu->getMenuItem($activeTopMenuItem);
    if ($contentMenuItem != null) {
        $contentMenuItem->setActive();
        $contentMenu = $contentMenuItem->getSubMenu();
    
        $activeMenuItem = $contentMenu->getMenuItem($active);
        if ($activeMenuItem != null) {
            $activeMenuItem->setActive();
        }
    }
    $baseUrl = $request->getApplicationPath();
?>

                    <div id="global-menu">
                        <?php foreach ($menu->getMenuItems() as $menuItem): ?>
                        <dl id="global-menu-<?php echo $menuItem->getId(); ?>">
                            <dt>
                                <a href="<?php echo $baseUrl . $menuItem->getTarget(); ?>"><?php echo $menuItem->getTitle(); ?></a>
                            </dt>
                            <?php
                            $subMenuItems = $menuItem->getSubMenu()->getMenuItems();
                            if ($menuItem->getId() == 'content' && count($subMenuItems) == 1):
                                $siteMenuItem = array_shift($subMenuItems);
                                $subMenuItems = $siteMenuItem->getSubMenu()->getMenuItems();
                            endif;
                            
                            foreach ($subMenuItems as $subMenuItem): ?>
                            <dd<?php if ($subMenuItem->isActive()): ?> class="active"<?php endif; ?>>
                                
                                <?php if ($subMenuItem->hasSubMenu()): ?>
                                <dl>
                                    <dt><?php echo $subMenuItem->getTitle(); ?></dt>
                                    <?php foreach ($subMenuItem->getSubMenu()->getMenuItems() as $subSubMenuItem): ?>
                                    <dd<?php if ($subSubMenuItem->isActive()): ?> class="active"<?php endif; ?>>
                                        <a href="<?php echo $baseUrl . $subSubMenuItem->getTarget(); ?>"><?php echo $subSubMenuItem->getTitle(); ?></a>
                                    </dd>
                                    <?php endforeach; ?>
                                </dl>
                                <?php else: ?>
                                <a id="global-menu-item-<?php echo $menuItem->getId() . '-' . $subMenuItem->getId(); ?>" href="<?php echo $baseUrl . $subMenuItem->getTarget(); ?>"><?php echo $subMenuItem->getTitle(); ?></a>
                                <?php endif; ?>

                            </dd>
                            <?php endforeach; ?>
                        </dl>
                            <?php endforeach; ?>
                    </div>